package com.baizhi.controller;


import com.alibaba.fastjson.JSON;
import com.baizhi.entity.User;
import com.baizhi.service.UserService;
import com.baizhi.service.UserServiceImpl;
import io.goeasy.GoEasy;
import io.goeasy.publish.GoEasyError;
import io.goeasy.publish.PublishListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("userEcharts")
    public Map<String, Object> userCount(){
        return userService.queryMonthAndCount();

    }

    @RequestMapping("queryByPage")
    public Map<String,Object> queryByPage(int page){
       int  size = 3;
        return userService.queryByPage(page,size); //如果切点切中了该方法 会先执行环绕通知
    }

    @RequestMapping("updateStatus")
    public void updateStatus(String id,int status){
        userService.updateStatus(id,status);
    }

    @RequestMapping("delete")
    public void delete(String id){
        userService.delete(id);
    }

    @RequestMapping("add")
    public void add(MultipartFile photo,String username,String phone,String brief){
        System.out.println(photo.getOriginalFilename());
        System.out.println(username);
        System.out.println(phone);
        System.out.println(brief);
        User user = new User(null,username,phone,null,brief,null,null,null,null);
        userService.add(photo,user);
    }

    @RequestMapping("export")
    public void export(Integer page){
        userService.export(page,3);
    }
}
